
package com.creditratingtypemodule.dao;
import com.creditratingtypemodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbCreditRatingTypeDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbCreditRatingType tbCreditRatingType=null;
    private List<TbCreditRatingType> tbCreditRatingTypeList=null;
    private Map<Integer,TbCreditRatingType> mapCreditRationgType=null;
    public boolean add(TbCreditRatingType inTbCreditRatingType){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_CreditRatingType(CreditRatingTypeName,CreditRatingTypeMemo) values(?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbCreditRatingType.getCreditRatingTypeName());
        pt.setString(2,inTbCreditRatingType.getCreditRatingTypeMemo());
       
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public boolean del(int inCreditRatingTypeId){
        return UtilDAO.del("Tb_CreditRatingType", "CreditRatingTypeId", inCreditRatingTypeId);
    }
    public boolean edit(TbCreditRatingType inTbCreditRatingType){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_CreditRatingType set  CreditRatingTypeName=?,CreditRatingTypeMemo=? where CreditRatingTypeId=?";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbCreditRatingType.getCreditRatingTypeName());
        pt.setString(2,inTbCreditRatingType.getCreditRatingTypeMemo());
        pt.setInt(3,inTbCreditRatingType.getCreditRatingTypeId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public TbCreditRatingType getTbCreditRatingTypeByCreditRatingTypeId(int inCreditRatingTypeId) {
        tbCreditRatingType=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_CreditRatingType where CreditRatingTypeId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inCreditRatingTypeId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbCreditRatingType == null)tbCreditRatingType = getTbCreditRatingType(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbCreditRatingType;
    }
    public List<TbCreditRatingType> getTbCreditRatingTypeAll() {
        tbCreditRatingTypeList=new ArrayList<TbCreditRatingType>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_CreditRatingType";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbCreditRatingTypeList.add(getTbCreditRatingType(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
        	ConnectDB.closeSqlConnection();
        }
        return tbCreditRatingTypeList;
    }
    /**
     * 
     *@author qingyu zhang
     *@function:
     * @return
     *2011-5-13
     *下午04:50:43
     *ProjectManager
     *com.creditratingtypemodule.dao
     *Map<Integer,TbCreditRatingType>
     */
    public Map<Integer,TbCreditRatingType> getTbCreditRatingType(){
    	mapCreditRationgType = new HashMap<Integer,TbCreditRatingType>();
    	try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_CreditRatingType";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
            	mapCreditRationgType.put(getTbCreditRatingType(rs).getCreditRatingTypeId(), getTbCreditRatingType(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
        	ConnectDB.closeSqlConnection();
        }
        return mapCreditRationgType;
    }
    public List<TbCreditRatingType> getTbCreditRatingTypeAll(VskPage vp) {
        tbCreditRatingTypeList=new ArrayList<TbCreditRatingType>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_CreditRatingType";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_CreditRatingType", "CreditRatingTypeId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbCreditRatingTypeList.add(getTbCreditRatingType(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbCreditRatingTypeList;
    }
    public TbCreditRatingType getTbCreditRatingType(ResultSet rs) throws Exception{
        TbCreditRatingType tbCreditRatingType = new TbCreditRatingType();
        tbCreditRatingType.setCreditRatingTypeId(rs.getInt("CreditRatingTypeId"));
        tbCreditRatingType.setCreditRatingTypeName(rs.getString("CreditRatingTypeName"));
        tbCreditRatingType.setCreditRatingTypeMemo(rs.getString("CreditRatingTypeMemo"));
        tbCreditRatingType.setCreateTime(rs.getString("CreateTime"));
        return tbCreditRatingType;
    }
}
